package net.cyan.proteus.report;

import java.util.List;

/**
 * 
 * @author camel
 * @date 2008-6-21
 */
public abstract class StatFunction implements ReportFunction
{
    public StatFunction()
    {
    }

    public Object call(String s, ReportContext context) throws Exception
    {
        List<Object> stats = context.getStats();
        return stats == null ? null : call(stats, s, context);
    }

    protected Object call(List datas, String expression, ReportContext context) throws Exception
    {
        int n = datas.size();
        Object[] values = new Object[n];
        for (int i = 0; i < n; i++)
            values[i] = context.eval(expression, datas.get(i));

        return call(values);
    }

    protected abstract Object call(Object[] values) throws Exception;
}
